home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Hyper Stacks 1994 May
/
Hyper Stacks (Pacific HiTech)(1994)[Mac].iso
/
HyperTalk
/
RegionPackage
/
Picture Window ƒ
/
WDEF Demo.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-12-10
|
3KB
|
150 lines
/* trivial demo of Picture Window WDEF, Nigel Perry 90 */
/* Comments? This program is trivial… */
#include "PictWindow.h"
#include "WDEFGlobals.h"
#define NIL ((void *)0)
#define FRONTWIN ((WindowPtr)-1)
/* used to check if window was framed */
framed(w, wl)
WindowPtr w, *wl;
{ int i;
for(i = 0; i < 16; i++)
{ if(w == *wl++)
return(i & PW_AddFrame);
}
return(0);
}
main()
{ int i, v, h, stop;
Rect r1, r2;
WindowPtr w[16], wind;
PicHandle p1, p2, p3, p4;
EventRecord event;
WDEFGlobals *gp;
Rect size;
InitGraf(&thePort);
InitFonts();
FlushEvents(everyEvent,0);
InitWindows();
InitMenus();
TEInit();
InitDialogs(NIL);
InitCursor();
if(!doDialog()) return;
if(GetWDEFGlobals(true, &gp)) return;
/* some pictures to draw */
p1 = (PicHandle)GetResource('PICT', 103);
p2 = (PicHandle)GetResource('PICT', 104);
p3 = (PicHandle)GetResource('PICT', 101);
p4 = (PicHandle)GetResource('PICT', 102);
r1.top = 16; r1.left = 16; r1.bottom = 106; r1.right = 86;
i = 0;
gp->pic = p1;
gp->frame = p2;
gp->flags.clonePic = gp->flags.cloneFrame = false;
gp->flags.sharePic = gp->flags.shareFrame = true;
for(v = 0; v <= 240; v += 80)
for(h = 0; h <= 384; h += 128)
{ r2 = r1;
OffsetRect(&r2, h, v);
if(i == 12) { gp->pic = p3; gp->frame = p4; }
w[i] = NewWindow(NIL, &r2, "\p", true, PictWDEF | i, FRONTWIN, false, 0);
/* NewWindow() will not draw the window's picture,
calling CheckUpdate() will fix this - all subsequent
redraws will be handled automatically by QD
*/
CheckUpdate(&event);
i++;
}
stop = 0;
size.left = 4; size.right = 32767;
size.top = 4; size.bottom = 32767;
r1.top = 0; r1.left = 0; r1.bottom = 32767; r1.right = 32767;
while(!stop)
{ if( GetNextEvent(everyEvent, &event) )
switch( event.what )
{ case updateEvt:
BeginUpdate((WindowPtr)event.message);
EndUpdate((WindowPtr)event.message);
break;
case keyDown:
stop = 1;
break;
case mouseDown:
switch( FindWindow(event.where, &wind) )
{ case inContent:
if( wind != FrontWindow() ) SelectWindow(wind);
else
{ SetPort(wind);
FillRect(&r1, gray);
while( StillDown() );
EraseRect(&r1);
}
break;
case inDrag:
if( framed(wind, w) )
{ if( wind != FrontWindow() )
SelectWindow(wind);
else
DragWindow(wind, event.where, &screenBits.bounds);
}
else if( event.modifiers & 0x0800 ) /* option key */
{ /* in asm as GrowWindow returns a long and
SizeWindow wants two ints… */
asm
{ subq.l #4,a7
move.l wind,-(a7)
move.l event.where,-(a7)
pea size
_GrowWindow
move.l (a7)+,d0
beq.s @nogrow
move.l wind,-(a7)
move.l d0,-(a7)
move.w #0,-(a7)
_SizeWindow
; CopyRgn(strucRgn, updateRgn) -> invalidate
; whole window area
move.l wind,a0
move.l OFFSET(WindowRecord,strucRgn)(a0),-(a7)
move.l OFFSET(WindowRecord,updateRgn)(a0),-(a7)
_CopyRgn
nogrow:
}
}
else
DragWindow(wind, event.where, &screenBits.bounds);
break;
default:
break;
}
break;
default:
break;
}
}
/* clean up */
for(i = 0; i < 16; i++) DisposeWindow(w[i]);
ReleaseResource(p1);
ReleaseResource(p2);
ReleaseResource(p3);
ReleaseResource(p4);
}